home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / etc / init.d / autoconfig < prev    next >
Text File  |  2006-02-01  |  7KB  |  303 lines

  1. #!/sbin/runscript
  2. # Copyright 1999-2005 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Header: /var/cvsroot/gentoo/src/livecd-tools/autoconfig,v 1.42 2005/08/30 17:52:45 wolf31o2 Exp $
  5.  
  6. DHCP="yes"
  7. DETECT="yes"
  8. GPM="yes"
  9. PCMCIA="no"
  10. HOTPLUG="yes"
  11. APM="no"
  12. ACPI="yes"
  13. IDEDMA="yes"
  14. ALSA="yes"
  15. X11="yes"
  16.  
  17. get_config() {
  18.     CMDLINE="$(cat /proc/cmdline)"
  19.  
  20.     for x in ${CMDLINE} ; do
  21.         if [ "${x}" = "nodetect" ]
  22.         then
  23.             DETECT="no"
  24.             GPM="no"
  25.             HOTPLUG="no"
  26.             APM="no"
  27.             ACPI="no"
  28.             ALSA="no"
  29.             X11="no"
  30.         fi
  31.  
  32.         if [ "${x}" = "nodhcp" ]
  33.         then
  34.             DHCP="no"
  35.         fi
  36.  
  37.         if [ "${x}" = "nogpm" ]
  38.         then
  39.             GPM="no"
  40.         fi
  41.  
  42.         if [ "${x}" = "dopcmcia" ]
  43.         then
  44.             PCMCIA="yes"
  45.         fi
  46.     
  47.         if [ "${x}" = "doapm" ]
  48.         then
  49.             APM="yes"
  50.             ACPI="no"
  51.         fi
  52.  
  53.         if [ "${x}" = "acpi=on" -o "${x}" = "acpi=force" ]
  54.         then
  55.             APM="no"
  56.             ACPI="yes"
  57.         fi
  58.  
  59.         if [ "${x}" = "ide=nodma" ]
  60.         then
  61.             IDEDMA="no"
  62.         fi
  63.  
  64.         if [ "${x}" = "nohotplug" ]
  65.         then
  66.             HOTPLUG="no"
  67.         fi
  68.  
  69.         if [ "${x}" = "nosound" ]
  70.         then
  71.             ALSA="no"
  72.         fi
  73.  
  74.         if [ "${x}" = "nox" ]
  75.         then
  76.             X11="no"
  77.         fi
  78.     done
  79. }
  80.  
  81. depend() {
  82.     need modules
  83.     before net
  84. #    provide gpm pcmcia apmd acpid coldplug hdparm alsasound x-setup
  85. }
  86.  
  87. # Checks whether a service will be started by autoconfig.
  88. # Usage: check_svc var service [service_alternative]
  89. check_svc() {
  90.     if [ "$1" = "yes" ]; then
  91.         if [ -x "/etc/init.d/$2" ]; then
  92.             echo "$2"
  93.         elif [ -n "$3" -a -x "/etc/init.d/$3" ]; then
  94.             echo "$3"        
  95.         fi    
  96.     fi    
  97. }
  98.  
  99. # Prints an ordered list of services that will be started by autoconfig.
  100. list_services() {
  101.     get_config
  102.  
  103.     local svcs="$(check_svc ${APM} apmd)"
  104.     svcs="${svcs} $(check_svc ${ACPI} acpid)"
  105.     svcs="${svcs} $(check_svc ${IDEDMA} hdparm)"
  106.     svcs="${svcs} $(check_svc ${PCMCIA} pcmcia)"
  107.     svcs="${svcs} $(check_svc ${GPM} gpm)"
  108.     svcs="${svcs} $(check_svc ${HOTPLUG} coldplug hotplug)"
  109.     svcs="${svcs} $(check_svc ${ALSA} alsasound)"
  110.  
  111.     echo ${svcs}
  112. }
  113.  
  114. start() {
  115.     echo "0" > /proc/sys/kernel/printk
  116.     get_config
  117.     if [ "${DETECT}" = "yes" ]
  118.     then
  119.         ebegin ${WARN}"Hardware detection started"
  120.         PC=$(awk -F: '/^processor/{printf "Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>/dev/null)
  121.         ebegin ${GOOD}"${PC}"
  122.         eend        
  123.         [ -x /usr/sbin/hwsetup ] && hwsetup -p >/dev/null
  124.         eend
  125.     else
  126.         ebegin ${WARN}"Hardware detection disabled via cmdline$NORMAL"
  127.     fi
  128.  
  129.     if [ "${APM}" = "yes" ]
  130.     then
  131.         modprobe apm power_off=1 >/dev/null 2>&1 && ebegin ${GOOD}"APM BIOS found, power management functions enabled.${NORMAL}"
  132.         [ -x /etc/init.d/apmd ] && start_service apmd
  133.     else
  134.         ebegin ${GOOD}"Not Loading APM Bios support.${NORMAL}"
  135.         eend
  136.     fi
  137.  
  138.     if [ "${ACPI}" = "yes" ]
  139.     then
  140.         modprobe processor >/dev/null 2>&1 && ebegin ${GOOD} ACPI power management functions enabled.${NORMAL} && modprobe thermal >/dev/null
  141.         modprobe fan >/dev/null 2>&1
  142.         modprobe button >/dev/null 2>&1
  143.         modprobe battery >/dev/null 2>&1
  144.         modprobe ac >/dev/null 2>&1
  145.         [ -x /etc/init.d/acpid ] && start_service acpid
  146.         eend
  147.     fi
  148.  
  149.     if [ "${IDEDMA}" = "yes" ]
  150.     then
  151.         [ -x /etc/init.d/hdparm ] && start_service hdparm
  152.     fi
  153.  
  154.     if [ "${PCMCIA}" = "yes" ]
  155.     then
  156.         ebegin ${HILITE} "PCMCIA enabled via cmdline"
  157.         [ -x /etc/init.d/pcmcia ] && start_service pcmcia
  158.     fi
  159.  
  160.     if [ "${DHCP}" = "no" ]
  161.     then
  162.         sed -i -e '/^ifconfig_eth.*dhcp.*/ s/^/#/' \
  163.             -e '/^iface_eth.*dhcp.*/ s/^/#/' \
  164.             -e '/^config_eth.*dhcp.*/ s/^/#/' \
  165.             /etc/conf.d/net
  166.         ebegin ${BAD}"Skipping DHCP broadcast detection as requested on boot commandline."
  167.     fi
  168.  
  169.     #Read in what hwsetup has found
  170.     [ -f /etc/sysconfig/knoppix ] && . /etc/sysconfig/knoppix
  171.     [ -f /etc/sysconfig/gentoo ] && . /etc/sysconfig/gentoo
  172.  
  173.     # Mouse
  174.     if [ -n "${MOUSE_DEVICE}" ]
  175.     then
  176.         ebegin ${GOOD}"Mouse is ${HILITE}${MOUSE_FULLNAME}${GOOD} at ${HILITE}${MOUSE_DEVICE}${NORMAL}"
  177.         source /etc/sysconfig/mouse
  178.         if [ -x /usr/sbin/gpm ]
  179.         then
  180.             if [ $(grep "#MOUSE=${MOUSETYPE}" /etc/conf.d/gpm) ]
  181.             then
  182.                 sed -i "\@MOUSE=${MOUSETYPE}@s@^#@@" /etc/conf.d/gpm
  183.             else
  184.                 echo "MOUSE=${MOUSETYPE}" >>/etc/conf.d/gpm
  185.             fi
  186.             if [ $(grep "#MOUSEDEV=${DEVICE}" /etc/conf.d/gpm) ]
  187.             then
  188.                 sed -i "\@MOUSEDEV=${DEVICE}@s@^#@@" /etc/conf.d/gpm
  189.             else
  190.                 echo "MOUSEDEV=${DEVICE}" >>/etc/conf.d/gpm
  191.             fi
  192.             if [ "${GPM}" = "yes" ]
  193.             then
  194.                 [ -x /etc/init.d/gpm ] && start_service gpm
  195.             fi
  196.         fi
  197.         eend
  198.     fi
  199.  
  200.     if [ "${HOTPLUG}" = "yes" ]
  201.     then
  202.         #Check whether we should be using hotplug or coldplug
  203.         if [ -x /etc/init.d/coldplug ]
  204.         then
  205.             start_service coldplug
  206.         elif [ -x /etc/init.d/hotplug ]
  207.         then
  208.             start_service hotplug
  209.         fi
  210.     else
  211.         ebegin ${BAD}"Hotplug disabled via cmdline${NORMAL}"
  212.     fi
  213.  
  214.     if [ "${DETECT}" = "no" ]
  215.     then
  216.         DHCP="no"
  217.     fi
  218.  
  219.     if [ "${DETECT}" = "yes" ]
  220.     then
  221.         NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
  222.     fi
  223.  
  224.     if [ -n "${NETDEVICES}" ]
  225.     then
  226.         for nics in ${NETDEVICES}
  227.         do
  228.             if [ "${DHCP}" = "yes" ]
  229.             then
  230.                 ebegin ${GOOD}"Network device${HILITE}${nics}${GOOD} detected,${WARN} DHCP broadcasting for IP.${NORMAL}"
  231.                 dhcpcd -n -h $(hostname) &
  232.             fi
  233.             eend
  234.         done
  235.     else
  236.         ebegin ${BAD}"No Network device auto detected.${NORMAL}"
  237.     fi
  238.  
  239.     if [ "${DETECT}" = "yes" ]
  240.     then
  241.         [ -x /etc/init.d/mkxf86config ] && start_service mkxf86config
  242.     fi
  243.  
  244.     if [ "${ALSA}" = "yes" ]
  245.     then
  246.         if [ -n "${SOUND_FULLNAME}" -o -n "${SOUND_DRIVER}" ]
  247.         then
  248.             ebegin ${GOOD}"Soundcard:"
  249.             eend
  250.             [ -n "${SOUND_FULLNAME}" ] 
  251.             ebegin "              ${WARN}${SOUND_FULLNAME}"
  252.             [ -n "${SOUND_DRIVER}" ] 
  253.             ebegin ${WARN}"              driver = ${SOUND_DRIVER}"${HILITE}
  254.             if [ -x /etc/init.d/alsasound ]
  255.             then
  256.                 start_service alsasound
  257.             else
  258.                 ebegin ${WARN}"/etc/init.d/alsasound not found, skipping."
  259.                 einfo "You will need to set volume controls manually."
  260.             fi
  261.             for i in $(cat /proc/asound/cards | cut -d" " -f1)
  262.             do
  263.                 if [ -d /proc/asound/card$i ] && [ -x /usr/bin/amixer ]
  264.                 then
  265.                     amixer -c $i scontrols > /etc/amixer
  266.                     if [ -n "$(grep Master /etc/amixer)" ]
  267.                     then
  268.                         amixer -c $i -q set Master 33% unmute >/dev/null 2>&1
  269.                     fi
  270.                     if [ -n "$(grep PCM /etc/amixer)" ]
  271.                     then
  272.                         amixer -c $i -q set PCM 33% unmute >/dev/null 2>&1
  273.                     fi
  274.                     if [ -n "$(grep Mic /etc/amixer)" ]
  275.                     then
  276.                         amixer -c $i -q set Mic 33% mute cap >/dev/null 2>&1
  277.                     fi
  278.                     if [ -n "$(grep Wave /etc/amixer)" ]
  279.                     then
  280.                         amixer -c $i -q set Wave 33% unmute >/dev/null 2>&1
  281.                     fi
  282.                     if [ -n "$(grep Capture /etc/amixer)" ]
  283.                     then
  284.                         amixer -c $i -q set Capture 33% unmute cap >/dev/null 2>&1
  285.                     fi
  286.                 fi
  287.             done
  288.         fi
  289.     else
  290.         ebegin ${BAD}"Skipping ALSA detection as requested on boot commandline."
  291.     fi
  292.  
  293.     if [ "${X11}" = "no" ]
  294.     then
  295.         touch /etc/init.d/.noxdm
  296.     fi
  297.  
  298.     killall hwsetup 2>/dev/null
  299.     echo "6" > /proc/sys/kernel/printk
  300. }
  301.  
  302. # vim: ts=4
  303.